package com.syz.web.service.Impl;

import com.syz.web.dao.IStudentDao;
import com.syz.web.dao.Impl.StudentDaoImpl;
import com.syz.web.pojo.Student;
import com.syz.web.service.IStudentService;
import com.syz.web.util.PageInfo;

import java.util.List;

public class StudentServiceImpl implements IStudentService {

    IStudentDao studentDao=new StudentDaoImpl();

    @Override
    public boolean add(String name, String age, String gender,String banjiId,String address) {
        int count=studentDao.add(name,age,gender,banjiId,address);
        return count>0?true:false;
    }

    @Override
    public boolean deleteById(String id) {
        int count=studentDao.deleteById(id);
        return count>0?true:false;
    }

    @Override
    public List<Student> selectAll() {
        return studentDao.selectAll();
    }

    @Override
    public boolean update(String id, String name, String age, String gender,String address) {
        int count=studentDao.update(id,name,age,gender,address);
        return count>0?true:false;
    }

    @Override
    public Student getStudentUpdatePage(String id) {
        return studentDao.getStudentUpdatePage(id);
    }

    @Override
    public PageInfo<Student> selectByPage(Integer pageNo, Integer pageSize) {
        List<Student> list = studentDao.selectByPage(pageNo, pageSize);
        Integer totalCount = studentDao.selectTotalCount();
        int totalPage = (int)Math.ceil((double)totalCount / pageSize);
        PageInfo<Student> pageInfo = new PageInfo<>(list, totalPage, pageNo, pageSize);
        return pageInfo;
    }
}
